package com.itheima.test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/*
接收端 可以 一直接收
 */
public class ReveiveClient {

    public static void main(String[] args) throws IOException {
        //创建接收端对象
        DatagramSocket ds = new DatagramSocket(9999);
        //创建接收数据对象
        byte[] bytes = new byte[1024 * 64];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        while (true) {
            //接收数据
            ds.receive(dp);
            int length = dp.getLength();
            // 展示数据
            String s = new String(bytes, 0, length);
            System.out.println(s);
        }
        //释放资源
       // ds.close();

    }
}
